/****************************************************************************************
**  File: Graphics.hpp
**  Author: Asteroth
**  Date: 22/02/2009
****************************************************************************************/

#ifndef __GRAPHICS_HPP__
#define __GRAPHICS_HPP__

#define GD_DEFAULT_DEPTH 0.0f

class Graphics
{
    private:
        core::Matrix4x4 modelView, projection;
        Material material;
        int activeTexture;

    public:
    	Graphics()
        {
            modelView.makeIdentity();
            projection.makeIdentity();
            activeTexture = 0;
        }

        ~Graphics()
        {

        }

        inline void clear(bool colorBuffer = true, bool depthBuffer = false) {
            glClear((colorBuffer?GL_COLOR_BUFFER_BIT:0)|(depthBuffer?GL_DEPTH_BUFFER_BIT:0));
        }

        inline void setModelView(const core::Matrix4x4 &modelView) {
        	Graphics::modelView = modelView;
            glMatrixMode(GL_MODELVIEW);
            glLoadMatrixf(Graphics::modelView.M);
        }

        inline void setProjection(const core::Matrix4x4 &projection) {
        	Graphics::projection = projection;
            glMatrixMode(GL_PROJECTION);
            glLoadMatrixf(Graphics::projection.M);
            glMatrixMode(GL_MODELVIEW);
        }

        inline void setMaterial(const Material &material, GLenum face = GL_FRONT_AND_BACK) {
        	this->material = material;
        	glMaterialfv(face, GL_AMBIENT, material.ambient);
        	glMaterialfv(face, GL_DIFFUSE, material.diffuse);
        	glMaterialfv(face, GL_SPECULAR, material.specular);
        	glMaterialfv(face, GL_EMISSION, material.emission);
        	glMaterialf(face, GL_SHININESS, material.shininess);
        }

        inline void setActiveTexture(int texUnit) {
        	if (texUnit >= 0 && texUnit<settings.maxTextureUnits())
        	{
        		activeTexture = texUnit;
        		glActiveTextureARB(GL_TEXTURE0_ARB + texUnit);
        	}
        }

        inline core::Matrix4x4 getModelView() { return modelView; }
        inline core::Matrix4x4 getProjection() { return projection; }
        inline Material getMaterial() { return material; }
        inline int getActiveTexture() { return activeTexture; }
};

#endif
